//
//  UIBarButtonItem+ConvienceInit.swift
//  MyBlog
//
//  Created by 李芙蓉 on 16/3/4.
//  Copyright © 2016年 hanlei. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title:String?=nil, imageName:String?=nil, target:AnyObject, action:Selector) {
      
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = title {
            
            button.setTitle(t, forState: .Normal)
            
            button.setTitleColor(myTextColor, forState: .Normal)
            
            button.setTitleColor(myOrangeColor, forState: .Highlighted)
        }
        
        if let i = imageName {
            
            button.setImage(UIImage(named: i), forState: .Normal)
            
            button.setImage(UIImage(named: "\(i)_highlighted"), forState: .Highlighted)
        }
        
        button.sizeToFit()
        
        customView = button
    }
}